/**
 * Generali Solutions d'assurances - Tous droits réservés &copy; 2007 - 2010
 */
package fr.generali.accueilclient.client.assembler.output.p44;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import fr.generali.accueilclient.client.om.ITelephone;
import fr.generali.accueilclient.client.om.impl.Telephone;
import fr.generali.accueilclient.utils.constantes.TypeModeContact;
import fr.generali.refservcommuns.rce.demat.servperscom.ctc.gestioncontacts.DtoTelephone;

/**
 * Transforme un {@link DtoTelephone} en {@link ITelephone}
 * 
 * @author selrhazala
 */
@Component("dtoTelephone2TelephoneP44Converter")
public class DtoTelephone2TelephoneP44Converter implements Converter<DtoTelephone, ITelephone> {

    /**
     * LOGGER
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(DtoTelephone2TelephoneP44Converter.class);

    /**
     * {@inheritDoc}
     */
    public ITelephone convert(DtoTelephone input) {
        LOGGER.debug("assemble");
        ITelephone telephone = null;

        if (input != null) {
            telephone = new Telephone();

            if (input.getNumOrdre() != null) {
                telephone.setNumOrdre(input.getNumOrdre());
            }

            telephone.setNumero(input.getNumero());
            telephone.setType(input.getTypeTelephone());
            telephone.setNumeroPoste(input.getExtension());
            telephone.setPrecision(input.getPrecisionTelephone());
            telephone.setPrincipal(false);

            if (input.isListeRouge() != null) {
                telephone.setListeRouge(input.isListeRouge());
            }

            if (input.getCodeTypeModeContact() != null
                            && TypeModeContact.TYPE_MODE_CONTACT_PRO.getCode().equals(input.getCodeTypeModeContact())) {
                telephone.setProfessionnel(true);
            } else {
                telephone.setProfessionnel(false);
            }
        }

        return telephone;
    }
}
